Repository navigation
NXT-20954: Added custom typecheck for Typescript 7 - #405
Conversation
# Conflicts: # CHANGELOG.md # config/webpack.config.js
| const pluginName = 'EnactTypeScriptCheckPlugin'; | ||
|
|
||
| // Diagnostics are not reported for test and setup files, matching the fork-ts-checker issue filters. | ||
| const excludeFile = /(^|[\\/])__tests__[\\/]|\.(spec|test)\.[^\\/]+$|[\\/]src[\\/]setup(Proxy|Tests)\.[^\\/]+$/; |
There was a problem hiding this comment.
src/setupTests.ts and src/setupProxy.* are not excluded when tsc prints a relative path.
|
|
||
| cancel () { | ||
| if (this.child) { | ||
| this.child.kill(); |
There was a problem hiding this comment.
A tsc process stopped on Windows is not treated as cancelled. (optional)
There was a problem hiding this comment.
I checked this on Windows (Node 24) with the real child: the TS 7 bin/tsc wrapper that the plugin spawns. After child.kill(), the close event fires with code=null, signal='SIGTERM'. On Windows, libuv records the exit signal when TerminateProcess succeeds, so the result goes through the if (signal) branch and resolves as {cancelled: true}.
I will be beaving this as is
| }), | ||
| // TypeScript 7+ type checking via the tsc binary | ||
| tscPath && | ||
| new TypeScriptCheckPlugin({ |
There was a problem hiding this comment.
TypeScriptCheckPlugin is registered before ESLintPlugin and pushes its diagnostic during afterCompile. In enact serve, createCompiler keeps only errors[0], so an ESLint error from the same compilation is dropped from the terminal and the overlay when a type error is also present. enact pack still prints every error. Worth confirming this is acceptable, since on TypeScript 5/6 fork-ts-checker reports asynchronously and does not take that first slot.
There was a problem hiding this comment.
Thanks. The effect is real, but the order is the other way round. eslint-webpack-plugin pushes its error in processAssets (during seal), which runs before afterCompile. So the ESLint error is errors[0], and it was the TypeScript error that got dropped from the terminal. Plugin registration order doesn’t matter here, since the two plugins use different hooks. The browser overlay wasn’t affected: it receives all compilation errors and showed both (checked in the browser). enact pack prints all errors, as you said.
It still differed from TS 5/6, where fork-ts-checker printed separately and both errors were visible, so I fixed it.
Checklist
Issue Resolved / Feature Added
Follow-up to the TypeScript 6/7 support change (#404 ). That change lets TypeScript 7 apps build, but skips type checking for them entirely.
fork-ts-checker-webpack-pluginneeds the JS compiler API (createProgram), and TypeScript 7 doesn't ship it. As a result, type errors in TS 7 apps don't show up inenact pack/enact serve.This PR adds type checking for TypeScript 7 apps by running the
tscbinary that TS 7 ships.Resolution
New
config/TypeScriptCheckPlugin.js: a webpack plugin that runstsc --project tsconfig.json --noEmit --skipLibCheck --incremental --pretty falsewith Node. Build info goes tonode_modules/.cache/tsconfig.tsbuildinfo, the same file fork-ts-checker used.tscstarts each time webpack starts compiling (run/watchRun) and runs while webpack bundles.afterCompile), the plugin waits fortscand adds each diagnostic to the compilation as an error. Existing error output, exit code 1 on failure and the dev-server overlay all work without other changes.TSC_COMPILE_ON_ERROR=true, diagnostics are added as warnings instead, as with the existing checker plugin.__tests__,*.spec.*/*.test.*,src/setupProxy.*,src/setupTests.*) are skipped, matching fork-ts-checker's filters.tsccan't run, the build gets a warning instead of failing.tscrun still in progress is stopped when a watch or serve session ends.config/webpack.config.js:resolveLegacyTypeScript()becomesresolveTypeScript(). It returns{typescriptPath}when the app'stypescriptpackage hascreateProgram(TS 5/6, still handled by fork-ts-checker). Otherwise it returns{tscPath}from the package'sbinfield (TS 7, handled by the new plugin). The skip warning now only appears whentypescriptcan't be resolved at all.Additional Considerations
Test scenario
Setup:
cliand link it globally (npm linkinsidecli), soenactruns this branch.cd samples/tutorial-typescript && npm install(installstypescript@^7.0.2).src/views/MainPanel.tsx:const typeErrorProbe: number = 'not a number';
export {typeErrorProbe};
TypeScript 7 (new
TypeScriptCheckPlugin)enact pack.Failed to compile.withsrc/views/MainPanel.tsx(20,7)andTS2322: Type 'string' is not assignable to type 'number'.; exit code 1.enact pack -p.TSC_COMPILE_ON_ERROR=true enact pack(PowerShell:$env:TSC_COMPILE_ON_ERROR='true'; enact pack).TS2322is shown as a warning; exit code 0.enact serveand open the app in the browser.TS2322in the terminal and in the browser error overlay.const typeErrorProbe: number = 42;and save.Compiled successfully!and the overlay disappears.enact pack -p.TypeScript 6 regression (still uses
fork-ts-checker-webpack-plugin)npm install --no-save typescript@6, then runenact pack.> 20 | const typeErrorProbe ...); exit code 1.enact pack.Links
NXT-20954
Comments
Enact-DCO-1.0-Signed-off-by: Daniel Stoian (daniel.stoian@lgepartner.com)